package com.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.beans.Movie;
import com.beans.Person;
import com.bussiness.AdminBussinessProxy;
import com.constants.ServiceEndPoints;
import com.constants.UIMessages;

/**
 * Servlet implementation class ListMemberServlet
 */
public class ListMemberServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	AdminBussinessProxy adminBI = new AdminBussinessProxy(); 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListMemberServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession(true);
		RequestDispatcher dispatcher;
		Person[] person = null;
		Person[] allperson = null;
		
		try
		{
			Integer catId = Integer.parseInt(request.getParameter("category"));
			System.out.println("Category Id:"+ catId);
			
			adminBI.setEndpoint(ServiceEndPoints.AdminEndPoint);
			if(catId == 1){
				session.removeAttribute("listPersons1");
			person = adminBI.getAllPremiumMembers();
			session.setAttribute("listPersons", person);
			
			}
			if(catId == 2){
				session.removeAttribute("listPersons1");
				person = adminBI.getAllSimpleMembers();
				session.setAttribute("listPersons", person);
			}
			if(catId == 3){
				person = adminBI.getAllPremiumMembers();
				allperson = adminBI.getAllSimpleMembers();
				session.setAttribute("listPersons", person);
				session.setAttribute("listPersons1", allperson);
			}
			
				
			dispatcher = getServletContext().getRequestDispatcher("/listmembers.jsp");
			dispatcher.forward(request, response);
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
			session.setAttribute("ServerMessage", UIMessages.SERVICE_UNAVAILABLE);
			dispatcher = getServletContext().getRequestDispatcher("/listmembers.jsp");
			dispatcher.forward(request, response);
		}
	

	}

}
